<?php TPL::output('global/header_meta.tpl.htm'); ?>
<div class="aw-register-box">
    <div class="mod-head">
        <a href=""><img src="<?php echo G_STATIC_URL; ?>/css/<?php echo $this->template_name; ?>/img/login_logo.png" alt="" /></a>
        <h1><?php _e('找回密码'); ?></h1>
    </div>
    <div class="mod-body">
        <form class="aw-register-form" id="fpw_form" method="post" action="<?php echo $this->action_link?>">
            <ul>
                <li class="alert alert-danger collapse error_message">
                    <i class="icon icon-delete"></i><em></em>
                </li>
                <?php if($this->type == 'mobile'){?>
                    <li>
                        <input class="aw-register-email form-control" id="phone" name="mobile" type="text" placeholder="手机号" >
                    </li>
                    <li class="aw-register-verify">
                        <div class="embed-captcha"></div>
                        <p class="wait">正在加载验证码......</p>
                    </li>
                    <li>
                        <input class="aw-register-validate form-control" style="width: 175px;position:relative; left: -5px; display: inline-block;" id="smscode" type="text" placeholder="<?php _e('短信验证码'); ?>" name="smscode" tips="<?php _e('请输入短信验证码'); ?>" errortips="<?php _e('短信验证码不正确'); ?>" />
                        <button id="Smsbtn" type="button" style="width: 120px;position:relative; top:-2px;right: -5px;  display: inline-block;" class="btn btn-large btn-blue btn-block">获取验证码</button>
                    </li>
                <?php } else { ?>
                    <li>
                        <input class="aw-register-email form-control" type="text" placeholder="<?php _e('邮箱'); ?>" name="email" />
                    </li>
                    <!-- <li class="aw-register-verify">
                        <img  class="auth-img pull-right" id="captcha" onclick="this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);" src="">
                        <input class="form-control" type="text" name="seccode_verify" placeholder="<?php _e('验证码'); ?>"/>
                    </li> -->
                    <li class="aw-register-verify">
                        <div class="embed-captcha"></div>
                        <p class="wait">正在加载验证码......</p>
                    </li>
                <?php }?>
                <li class="clearfix">
                    <button class="btn btn-large btn-blue btn-block" id="zhuce"><?php _e('下一步'); ?></button>
                </li>

                <?php if($this->other_valid and get_hook_info('mobile_regist')['state']==1){?>
                <li class="last" style="cursor: pointer">
                    <a href="account/find_password/type-<?php echo $this->other_valid['type']?>" class="pull-right" ><?php echo $this->other_valid['name'] ?></a>
                </li>
                <?php }?>
            </ul>
        </form>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function ()
    {
        /*仿刷新：检测是否存在cookie*/
        if($.cookie("captcha")){
            var count = $.cookie("captcha");
            var btn = $('#Smsbtn');
            $('#Smsbtn').prop('disabled', true);
            btn.text(count+'秒');
            var resend = setInterval(function(){
                count--;
                if (count > 0){
                    // btn.text(count+'秒后可重新获取')
                    btn.text(count+'秒');
                    $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
                }else {
                    $('#Smsbtn').prop('disabled', false);
                    clearInterval(resend);
                    btn.text("获取验证码")
                }
            }, 1000);
        }

        var handlerEmbed = function (captchaObj) {
            $("#Smsbtn").click(function (e) {
                var phonereg = /^1[3456789]\d{9}$/;
                var mobile = $('input[name="mobile"]').val();

                if(mobile=='' ){
                    AWS.alert("请输入手机号");
                    return false;
                }
                if(!phonereg.test(mobile)){
                    AWS.alert("手机号格式不正确");
                    return false;
                }
                if($('#Smsbtn').text()!="获取验证码"){
                    return false;
                }

                var validate = captchaObj.getValidate();
                if (!validate) {
                    AWS.alert("请先完成验证");
                    return false;
                } else{
                    $.post(G_BASE_URL + '/account/ajax/check_mobile/',{
                        mobile:mobile,
                        type:'find_password',
                    }, function (result)
                    {
                        if (result.errno == -1)
                        {
                            AWS.alert(result.err);
                            captchaObj.reset();
                            return false;
                        }else{
                            $.ajax({
                                url: G_BASE_URL + '/tools/sendSms/',
                                type: "post",
                                dataType: "json",
                                data: {
                                    mobile: mobile,
                                    challenge: '',
                                    geetest_challenge: validate.geetest_challenge,
                                    geetest_validate: validate.geetest_validate,
                                    geetest_seccode: validate.geetest_seccode,
                                    client_type: 'web',
                                    genre: '1'
                                },
                                success: function (result) {
                                    if(result.errno == -1)
                                    {
                                        AWS.alert(result.err);
                                        captchaObj.reset(); // 调用该接口进行重置 
                                        return false;
                                    }else
                                    {
                                        AWS.alert(result.err);
                                        var count = 60;
                                        var inl = setInterval(function () {
                                            $('#Smsbtn').prop('disabled', true);
                                            count -= 1;
                                            var text = count + ' 秒';
                                            $.cookie("captcha", count, {path: '/', expires: (1/86400)*count});
                                            $('#Smsbtn').text(text);
                                            if (count <= 0) {
                                                clearInterval(inl);
                                                $('#Smsbtn').prop('disabled', false);
                                                $('#Smsbtn').text('获取验证码');
                                            }
                                        }, 1000);
                                        return true;
                                    }

                                }
                            });
                        }
                    }, 'json');
                }
            });
            $('#zhuce').click(function(){
                var validate = captchaObj.getValidate();
                if (!validate) {
                    AWS.alert("请先完成验证");
                    return false;
                } else{
                    AWS.ajax_post($('#fpw_form'), AWS.ajax_processer, 'error_message'); 
                    captchaObj.reset(); // 调用该接口进行重置 
                    return false;
                }
            });
            // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
            captchaObj.appendTo(".embed-captcha");
            captchaObj.onReady(function () {
                $(".wait").css('display','none');
            });
        };

        $.ajax({
            // 获取id，challenge，success（是否启用failback）
            url: G_BASE_URL+ "/account/slide_captcha/?t=" + (new Date()).getTime()+"&client_type='web'", // 加随机数防止缓存
            type: "get",
            dataType: "json",
            success: function (data) {
                var dataObj = eval('(' + data.rsm + ')');
                // 使用initGeetest接口
                // 参数1：配置参数
                // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
                initGeetest({
                    gt: dataObj.gt,
                    challenge: dataObj.challenge,
                    new_captcha: dataObj.new_captcha,
                    offline: !dataObj.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                    product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                    width: '100%' // 设置按钮宽度, 与父元素宽度一致
                }, handlerEmbed);
            }
        });

    });
</script>

<?php TPL::output('global/footer.tpl.htm'); ?>